﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using NetMicro.EventBus.Messages;

namespace NetMicro.EventBus.Persistences
{
    public interface IDelayMessageStorage
    {
        /// <summary>
        /// 保存延迟队列消息
        /// </summary>
        /// <param name="message"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<bool> SaveAsync(MessageStorageTransfer message,
          CancellationToken cancellationToken = default);

        /// <summary>
        /// 延迟消息添加锁
        /// </summary>
        /// <param name="id"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<bool> LockAsync(long id,
          CancellationToken cancellationToken = default);

        /// <summary>
        /// 删除发布完成延迟消息
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<bool> DeleteMessageAsync(long id, CancellationToken cancellationToken = default);

        /// <summary>
        /// 延迟消息释放锁
        /// </summary>
        /// <param name="id"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<bool> UnLockAsync(long id,
          CancellationToken cancellationToken = default);

        /// <summary>
        /// 延迟消息锁到期之后未释放的锁,释放锁
        /// </summary>
        /// <param name="id"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<bool> ExpireTimeUnLockAsync(
         CancellationToken cancellationToken = default);
        /// <summary>
        /// 获取需要发布的消息
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        Task<IEnumerable<MessageStorageTransfer>> GetMessagesAsync();
        /// <summary>
        /// 删除到期消息
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<bool> DeleteExpiresAsync(CancellationToken cancellationToken = default);
    }
}
